home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18335 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  52 lines

  1. Path: ix.netcom.com!news
  2. From: Bradd W. Szonye <bradds@ix.netcom.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: RE: Small question
  5. Date: 19 Apr 1996 09:49:47 GMT
  6. Organization: Netcom
  7. Message-ID: <01bb2dd5.d605aa00$c6c2b7c7@Zany.localhost>
  8. References: <4k822h$s8t@pub.news.uk.psi.net>
  9. NNTP-Posting-Host: det-mi6-06.ix.netcom.com
  10. X-NETCOM-Date: Fri Apr 19  4:49:47 AM CDT 1996
  11. X-Newsreader: Microsoft Internet News
  12.  
  13.  
  14. On Sunday, April 07, 1996, andrew oxenburgh wrote...
  15. > sence@ava.taby.se (Bjorn Osterman) writes:
  16. > > If I have 2 cpp files and i use the same global variable that i define
  17. > > in some file that both cpp-files includes. How do I tell the compiler
  18. > > that the variable is the same and that it shouldn't make space 2
  19. > > times?
  20. > > 
  21. > > 
  22. > > 
  23. > >   // bjorn@ava.taby.se
  24. > >   // http://www.ava.taby.se/www/sence
  25. > Bjorn,
  26. > Put the global once in a common header????
  27. > chz
  28. > andrewo
  29. Not exactly.
  30.  
  31. For, say, a global integer called "foo":
  32.  
  33. source file 1:
  34. extern int foo;
  35. int foo = 1;
  36.  
  37. source file 2:
  38. extern int foo;
  39.  
  40. The "extern" declarations can go in a header, or right in your source
  41. files.
  42. But make sure you define it only once (the = 1 line), especially in C++,
  43. which is less forgiving about such things than C is.
  44.  
  45.  
  46.